// loading.js
import ToastComponent from './toast.vue'

let $vm

const Toast = {
	install(Vue, options) {
		if (!$vm) {
			const ToastPlugin = Vue.extend(ToastComponent);

			$vm = new ToastPlugin({
				el: document.createElement('div')
			});
			document.body.appendChild($vm.$el);
		}

		$vm.show = false;
		$vm.type = 'loading',
		$vm.text = '数据加载中';

		let toast = {
			show(text,type) {
				$vm.show = true;
				$vm.type = type;
				$vm.text = text;
			},
			hide() {
				$vm.show = false;
			}
		};

		if (!Vue.$toast) {
			Vue.$toast = toast;
		}

		Vue.mixin({
			created() {
				this.$toast = Vue.$toast;
			}
		})
	}

}

export default Toast
